package com.example.composestudy.ui.widget

import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.example.composestudy.ui.theme.MyIcons
import com.example.composestudy.ui.theme.myIconFont

@Composable
inline fun IconFont(text: String,
                    modifier: Modifier = Modifier,
                    color: Color = MaterialTheme.colorScheme.primary,
                    size: Dp = 24.dp,
                    fontFamily: FontFamily = myIconFont,
                    letterSpacing: TextUnit = TextUnit.Unspecified,
                    textDecoration: TextDecoration? = null,
                    textAlign: TextAlign? = null,
                    lineHeight: TextUnit = TextUnit.Unspecified,
                    overflow: TextOverflow = TextOverflow.Clip,
                    softWrap: Boolean = true,
                    maxLines: Int = Int.MAX_VALUE,
                    minLines: Int = 1,
                    style: TextStyle = LocalTextStyle.current) {
    Text(text, modifier, color, size.dpToSp(), null, null, fontFamily, letterSpacing, textDecoration, textAlign, lineHeight, overflow, softWrap, maxLines, minLines,
        { }, style)
}

@Composable
fun Dp.dpToSp() = with(LocalDensity.current) { this@dpToSp.toSp() }

@Preview
@Composable
fun IconFontPreview(){
    IconFont(text = MyIcons.search, size = 30.dp, color = MaterialTheme.colorScheme.onPrimary)
}